//
//  PersonMenuController.m
//  DTSTONZJ
//
//  Created by wei wang on 2017/8/30.
//  Copyright © 2017年 wei wang. All rights reserved.
//

#import "PersonMenuController.h"
#import "PersonMenuView.h"
#import "PersonMenuTableViewCell.h"
//#import "PersonInfoViewController.h"
#import "SWRevealViewController.h"
//#import "MessgeViewController.h"
#import "Masonry.h"

@interface PersonMenuController ()<UITableViewDelegate,UITableViewDataSource>
/** tableView **/
@property(nonatomic,strong) UITableView *tableView;

/** personMenuSetting.plist **/
@property(nonatomic,strong) NSArray *settingPlist;
/** 顶部的个人信息展示 **/
@property(nonatomic,strong) PersonMenuView *personView;


@end

@implementation PersonMenuController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self masLayoutSubview];

}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
//    self.personView.nickNameLabel.text = EXRACT_OBJECT(NICKNAME);
//    [self.personView.headImageView sd_setImageWithURL:[NSURL URLWithString:EXRACT_OBJECT(IMAGE)] placeholderImage:[UIImage imageNamed:@"bg_jingshuiqi"]];
}

- (void)pushVC{
    
    /*
    SWRevealViewController *revealController = [self revealViewController];
    [revealController setFrontViewPosition:FrontViewPositionLeft animated:YES];
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"HomePage" bundle:nil];

    [self presentViewController:[[UINavigationController alloc]initWithRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"PersonInfoViewController"]]
                       animated:YES
                     completion:nil];
     */
}



#pragma mark - --------------------------UITableViewDataSource--------------------------

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.settingPlist.count;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.settingPlist[section] count];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    PersonMenuTableViewCell *cell = [[PersonMenuTableViewCell alloc]initWithSettingDic:self.settingPlist[indexPath.section][indexPath.row]
                                                                       reuseIdentifier:self.settingPlist[indexPath.section][indexPath.row][@"title"]];
    
    return cell;
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    SWRevealViewController *revealController = [self revealViewController];
    [revealController setFrontViewPosition:FrontViewPositionLeft animated:YES];
    switch (indexPath.row) {
        case 0:
        {
            

            
            break;
        }
            
        case 1:
        {
            /*
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            [self presentViewController:[[BaseNavigationController alloc]initWithRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"InforPswController"]]
                               animated:YES
                             completion:nil];
            
            break;
             */
            break;
        }
        case 2:
        {
            /*
            WebViewController *webVC = [[WebViewController alloc]init];
            webVC.localString = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
            [self presentViewController:[[BaseNavigationController alloc]initWithRootViewController:webVC] animated:YES completion:nil];
            [webVC setNavigationTitle:@"关于我们" titleColor:[UIColor blackColor]];
            break;
             */
            break;
        }
        case 3:
        {
            
            
            
            break;
        }
            
        default:
            break;
    };
    
}


- (UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        __weak UIView *superView = self.view;
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        [superView addSubview:_tableView];
        _tableView.scrollEnabled = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        
    }
    
    return _tableView;
    
}

- (NSArray *)settingPlist{
    
    if (!_settingPlist) {
        
        _settingPlist = [[NSArray alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"personMenuSetting" ofType:@"plist"]];
        
    }
    
    return _settingPlist;
    
}


- (PersonMenuView *)personView{
    
    if (!_personView) {
        __weak UIView *superView = self.view;
        _personView = [[PersonMenuView alloc]init];
        [_personView.eventBtn addTarget:self action:@selector(pushVC) forControlEvents:UIControlEventTouchUpInside];
        [superView addSubview:_personView];
        
    }
    
    return _personView;
    
}

- (void)masLayoutSubview{
    __weak UIView *superView = self.view;
    
    
    [self.personView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(superView.mas_top);
        make.left.mas_equalTo(superView.mas_left);
        make.right.mas_equalTo(superView.mas_right).multipliedBy(0.8);
        make.height.mas_equalTo(150);
        
    }];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.personView.mas_bottom).mas_offset(20);
        make.left.mas_equalTo(superView.mas_left);
        make.right.mas_equalTo(superView.mas_right);
        make.bottom.mas_equalTo(superView.mas_bottom);
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
